<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="律师姓名" prop="lawyerFullname">
        <el-input
          v-model="queryParams.lawyerFullname"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" type="index" width="50" />
      <el-table-column label="账号" align="center" prop="lawyerPhone" width="120" />
      <el-table-column label="律所" align="center" prop="lawfirmName" />
      <el-table-column label="姓名" align="center" prop="lawyerFullname"  width="80" />
      <el-table-column label="类别（等级）" align="center" prop="lawyerJoblevel" />
      <el-table-column label="地区" align="center" prop="lawyerAddress" />
      <el-table-column label="提交时间" align="center" prop="createdAt" width="160">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="60">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="handleStatusChange(scope.row, 'status')"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            class="text-red"
            icon="el-icon-remove-outline"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所属律所" prop="lawfirmId">
              <el-select v-model="form.lawfirmId" filterable placeholder="请选择" @change="handleLawfirmChange">
                <el-option v-for="item in lawfirmList" :key="item.id" :label="item.lawfirmFullname" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="律师类别" prop="lawyerGrade">
              <el-select v-model="form.lawyerGrade" placeholder="请选择">
                <el-option label="不选择" :value="0"></el-option>
                <el-option label="资深合伙人" :value="2"></el-option>
                <el-option label="合伙人" :value="3"></el-option>
                <el-option label="律师" :value="4"></el-option>
                <el-option label="顾问" :value="5"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
        <el-form-item label="会员等级" prop="memberLevel">
          <el-select v-model="form.memberLevel" placeholder="请选择">
             <el-option label="免费账户" :value="0"></el-option>
             <el-option label="名律堂线上会员" :value="2"></el-option>
             <el-option label="名律堂标准会员" :value="3"></el-option>
             <el-option label="名律堂高级会员" :value="4"></el-option>
             <el-option label="律师专委会成员" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="缴费状态" prop="fixVip">
          <el-select v-model="form.fixVip" placeholder="请选择">
             <el-option label="未缴费" :value="0"></el-option>
             <el-option label="已缴费" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="律师身份标识" prop="lawyerLevelMore">
          <el-checkbox-group v-model="lawyerLevelMore">
            <el-checkbox v-for="dict in dict.type.lawyer_Level" :key="dict.value" :label="Number(dict.value)">{{ dict.label }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="律师最高身份标识" prop="lawyerLevel" label-width="140px">
          <el-select v-model="form.lawyerLevel" placeholder="请选择">
            <el-option label="不选择" :value="0"></el-option>
            <el-option v-for="item in dict.type.lawyer_Level" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="照片形象" prop="lawyerLogo">
          <el-upload ref="img" :show-file-list="false" :action="imgAction" :before-upload="beforeUpload"
            :on-success="(res) => uploadSuccess(res, 'lawyerLogo')" list-type="picture-card" accept="image/*">
            <img v-if="form.lawyerLogo" :src="form.lawyerLogo | fullImgUrl" width="148" height="148" style="object-fit: contain;" />
            <i v-else class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传不超过 <b style="color: red;">5MB</b> 的 <b style="color: red;">png/jpg/jpeg</b>文件，且不超过1个</div>
          </el-upload>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="个人封面" prop="lawyerCover">
          <el-upload ref="img" :show-file-list="false" :action="imgAction" :before-upload="beforeUpload"
            :on-success="(res) => uploadSuccess(res, 'lawyerCover')" list-type="picture-card" accept="image/*">
            <img v-if="form.lawyerCover" :src="form.lawyerCover | fullImgUrl" width="148" height="148" style="object-fit: contain;" />
            <i v-else class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传不超过 <b style="color: red;">5MB</b> 的 <b style="color: red;">png/jpg/jpeg</b>文件，且不超过1个</div>
          </el-upload>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="姓名" prop="lawyerFullname">
          <el-input v-model="form.lawyerFullname" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="出生年份" prop="liveDate">
          <el-date-picker type="date" v-model="form.liveDate" placeholder="请选择" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="性别" prop="lawyerSex">
          <el-select v-model="form.lawyerSex" placeholder="请选择">
             <el-option label="男" :value="1"></el-option>
             <el-option label="女" :value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="地区" prop="lawyerCitys">
          <el-select v-model="form.lawyerCitys" placeholder="请选择">
            <el-option v-for="item in dict.type.business_citys" :key="item.value" :label="item.label" :value="Number(item.value)"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="办公地址" prop="lawyerAddress">
          <el-input v-model="form.lawyerAddress" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="邮箱" prop="lawyerEmail">
          <el-input v-model="form.lawyerEmail" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="电话" prop="lawyerContact">
          <el-input v-model="form.lawyerContact" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="手机号（账号）" prop="lawyerTelnum" label-width="140px">
          <el-input v-model="form.lawyerTelnum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="行业" prop="lawyerWorkIndustry">
          <el-input v-model="form.lawyerWorkIndustry" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="毕业院校" prop="lawyerWorkIndustry">
          <el-input v-model="form.lawyerWorkIndustry" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="执业起始年份" prop="lawyerBusinessyear">
          <el-date-picker type="year" v-model="form.lawyerWorkIndustry" placeholder="选择年" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="学历" prop="lawyerEducation">
          <el-select v-model="form.lawyerEducation" placeholder="请选择">
            <el-option label="学士" value="学士"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="博士" value="博士"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="工作语言" prop="lawyerWorkLanguage">
          <el-input v-model="form.lawyerWorkLanguage" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="职级" prop="lawyerJoblevel">
          <el-input v-model="form.lawyerJoblevel" placeholder="请输入" style="width: 140px;" />
          <el-checkbox class="ml10" v-model="form.lawyerJoblevelCert" :true-label="1" :false-label="0">已认证</el-checkbox>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="执业范围" prop="lawyerJobscope">
          <el-checkbox-group class="more-radio-group" v-model="lawyerJobscope">
            <el-checkbox label="中国" value="中国"></el-checkbox>
            <el-checkbox label="境外" value="境外"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="收费标准（小时费）" prop="lawyerFee" label-width="180px">
          <el-select v-model="form.lawyerFee" placeholder="请选择">
            <el-option v-for="item in dict.type.lawyer_fee" :key="item.value" :label="item.label" :value="Number(item.value)"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="团队人数" prop="lawyerTeamnumber">
          <el-select v-model="form.lawyerTeamnumber" placeholder="请选择">
            <el-option v-for="item in dict.type.team_number" :key="item.value" :label="item.label" :value="Number(item.value)"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="律师人数" prop="lawyerNum">
          <el-input v-model="form.lawyerNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="1-2年经验人数" prop="lawyerOtNum" label-width="140px">
          <el-input v-model="form.lawyerOtNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="3-4年经验人数" prop="lawyerTfNum" label-width="140px">
          <el-input v-model="form.lawyerTfNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="5年及以上经验人数" prop="lawyerFtNum" label-width="140px">
          <el-input v-model="form.lawyerFtNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="非律师人数" prop="notLawyerNum">
          <el-input v-model="form.notLawyerNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="顾问人数" prop="consultantNum">
          <el-input v-model="form.consultantNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="合伙人（本人除外）人数" prop="partnerNum" label-width="180px">
          <el-input v-model="form.partnerNum" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="团队成员" prop="lawyerTeammember">
          <el-input v-model="form.lawyerTeammember" type="textarea" :rows="3" placeholder="请输入" />
          <div class="text-warning">多个成员用"||"分隔</div>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="团队架构图" prop="lawyerTeamstructure">
          <el-upload ref="img" :show-file-list="false" :action="imgAction" :before-upload="beforeUpload"
            :on-success="(res) => uploadSuccess(res, 'lawyerTeamstructure')" list-type="picture-card" accept="image/*">
            <img v-if="form.lawyerTeamstructure" :src="form.lawyerTeamstructure | fullImgUrl('official')" width="148" height="148" style="object-fit: contain;" />
            <i v-else class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传不超过 <b style="color: red;">5MB</b> 的 <b style="color: red;">png/jpg/jpeg</b>文件，且不超过1个</div>
          </el-upload>
          <el-input v-model="form.lawyerTeamstructureTxt" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="团队人均年营收" prop="lawyerYearpercapita" label-width="180px">
          <el-input v-model="form.lawyerYearpercapita" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="业务类型" prop="lawyerBusinesstype">
          <el-select v-model="form.lawyerBusinesstype" placeholder="请选择">
             <el-option label="诉讼为主" :value="1"></el-option>
             <el-option label="非诉为主" :value="2"></el-option>
             <el-option label="两者均做" :value="4"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="擅长领域" prop="lawyerSpeciality">
          <el-radio-group class="more-radio-group" v-model="form.lawyerSpeciality">
            <el-radio v-for="item in specialityList" :key="item.id" :label="item.title" :value="item.val" style="min-width: 25%"></el-radio>
          </el-radio-group>
          <el-input class="other-input" v-show="form.lawyerSpeciality == '其他'" v-model="form.lawyerSpecialityMore" placeholder="请输入其他行业领域" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="次擅长领域" prop="lawyerSpecialityF">
          <el-checkbox-group class="more-radio-group" v-model="lawyerSpecialityF">
            <el-checkbox v-for="item in specialityList" :key="item.id" :label="item.title" :value="item.val" style="min-width: 25%"></el-checkbox>
          </el-checkbox-group>
          <el-input class="other-input" v-show="lawyerSpecialityF.includes('其他')" v-model="form.lawyerSpecialityFMore" placeholder="请输入其他行业领域" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="有经验业务领域" prop="lawyerSpecialityQ">
          <el-checkbox-group class="more-radio-group" v-model="lawyerSpecialityQ">
            <el-checkbox v-for="item in specialityList" :key="item.id" :label="item.title" :value="item.val" style="min-width: 25%"></el-checkbox>
          </el-checkbox-group>
          <el-input class="other-input" v-show="lawyerSpecialityQ.includes('其他')" v-model="form.lawyerSpecialityQMore" placeholder="请输入其他行业领域" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="行业领域" prop="expertIndustry">
          <el-checkbox-group class="more-radio-group" v-model="expertIndustry">
            <el-checkbox v-for="item in industryList" :key="item.id" :label="item.title" :value="item.val"></el-checkbox>
          </el-checkbox-group>
          <el-input class="other-input" v-show="expertIndustry.includes('其他')" v-model="form.expertIndustryMore" placeholder="请输入其他行业领域" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="资格证书" prop="lawyerCertificate">
          <el-input v-model="form.lawyerCertificate" type="textarea" :rows="3" placeholder="请输入" />
          <div class="text-warning">多个证书用","分隔</div>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="主要业绩" prop="lawyerPerformance">
          <el-input v-model="form.lawyerPerformance" type="textarea" :rows="3" placeholder="请输入" style="width: 80%;" />
          <el-checkbox class="ml10" v-model="form.lawyerPerformanceCert" :true-label="1" :false-label="0">已认证</el-checkbox>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="代表客户" prop="lawyerCustomer">
          <el-input v-model="form.lawyerCustomer" type="textarea" :rows="3" placeholder="请输入" />
          <div class="text-warning">多个客户用","分隔</div>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="个人简介" prop="lawyerSummary">
          <el-input v-model="form.lawyerSummary" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="工作经历" prop="lawyerWork">
          <el-input v-model="form.lawyerWork" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="主要著述" prop="lawyerResearchresult">
          <el-input v-model="form.lawyerResearchresult" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="团队信息" prop="lawyerTeam">
          <el-input v-model="form.lawyerTeam" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="首页推荐位" prop="isPoster">
        <el-select v-model="form.isPoster" placeholder="请选择">
          <el-option label="否" :value="0"></el-option>
          <el-option label="是" :value="1"></el-option>
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="资讯广告位" prop="isNewsPoster">
        <el-select v-model="form.isNewsPoster" placeholder="请选择">
          <el-option label="否" :value="0"></el-option>
          <el-option label="是" :value="1"></el-option>
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="案源广告位" prop="isCasePoster">
        <el-select v-model="form.isCasePoster" placeholder="请选择">
          <el-option label="否" :value="0"></el-option>
          <el-option label="是" :value="1"></el-option>
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="是否有展示位" prop="isHasShowPosition">
        <el-select v-model="form.isHasShowPosition" placeholder="请选择">
          <el-option label="否" :value="0"></el-option>
          <el-option label="是" :value="1"></el-option>
        </el-select>
      </el-form-item>
    </el-col>
      <el-col :span="24">
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="form.sort" :min="1"></el-input-number>
        </el-form-item>
      </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryList, getItem, delItem, addItem, updateItem } from "@/api/mobile/lawyer"
import { queryList as queryLawfirmList } from "@/api/official/lawfirm"
import { queryList as querySpecialityList } from "@/api/official/speciality"
import { queryList as queryIndustryList } from "@/api/official/industry"
import { getToken } from "@/utils/auth"

export default {
  name: "User",
  dicts: ['lawyer_Level','business_citys','lawyer_fee', 'team_number'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 律师导入参数
      upload: {
        // 是否显示弹出层（律师导入）
        open: false,
        // 弹出层标题（律师导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/amini/lawyer/importExcel"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isCheck: 1,
        searchtxt: null,
      },
      lawfirmList: [],
      specialityList: [],
      industryList: [],
      // 表单参数
      form: {},
      lawyerLevelMore: [],
      lawyerJobscope: [],
      lawyerSpecialityF: [],
      lawyerSpecialityQ: [],
      expertIndustry: [],
      // 表单校验
      rules: {
      },
      imgAction: `${process.env.VUE_APP_BASE_API}/common/commonUpload`,
    }
  },
  watch: {
    lawyerLevelMore: {
      handler(newVal) {
        this.form.lawyerLevelMore = newVal.join(',')
      },
      deep: true
    },
    lawyerJobscope: {
      handler(newVal) {
        this.form.lawyerJobscope = newVal.join(',')
      },
      deep: true
    },
    lawyerSpecialityF: {
      handler(newVal) {
        this.form.lawyerSpecialityF = newVal.join(',')
      },
      deep: true
    },
    lawyerSpecialityQ: {
      handler(newVal) {
        this.form.lawyerSpecialityQ = newVal.join(',')
      },
      deep: true
    },
    expertIndustry: {
      handler(newVal) {
        this.form.expertIndustry = newVal.join(',')
      },
      deep: true
    },
  },
  created() {
    queryLawfirmList({pageSize: 1000, isCheck: 1}).then(response => {
      this.lawfirmList = response.rows
    })
    querySpecialityList({pageSize: 1000, status: 1}).then(response => {
      this.specialityList = response.rows
    })
    queryIndustryList({pageSize: 1000}).then(response => {
      this.industryList = response.rows
    })
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      queryList(this.queryParams).then(response => {
        this.userList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null
      }
      this.lawyerLevelMore = []
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getItem(id).then(response => {
        this.form = response.data
        if(response.data.lawyerLevelMore){
          this.lawyerLevelMore = response.data.lawyerLevelMore.split(',')
        }
        if(response.data.lawyerJobscope){
          this.lawyerJobscope = response.data.lawyerJobscope.split(',')
        }
        if(response.data.lawyerSpecialityF){
          this.lawyerSpecialityF = response.data.lawyerSpecialityF.split(',')
        }
        if(response.data.lawyerSpecialityQ){
          this.lawyerSpecialityQ = response.data.lawyerSpecialityQ.split(',')
        }
        if(response.data.expertIndustry){
          this.expertIndustry = response.data.expertIndustry.split(',')
        }
        this.open = true
        this.title = `修改信息`
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateItem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addItem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除信息编号为"' + ids + '"的数据项？').then(function() {
        return delItem(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/amini/lawyer/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "律师导入"
      this.upload.open = true
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/user/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    // 状态修改
    handleStatusChange(row, field='status') {
      let text = row[field] == 0 ? "下线" : "上线"
      this.$modal.confirm(`确认要"${text}"该数据吗？`).then(function() {
        return updateItem({id :row.id, [field]: row[field]})
      }).then(() => {
        this.$modal.msgSuccess(text + "成功")
      }).catch(function() {
        row[field] = row[field] == "0" ? 1 : 0
      })
    },
    beforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 5
      if (!isRightSize) {
        this.$message.error('文件大小超过 5MB')
      }
      let isAccept = new RegExp('image/*').test(file.type)
      if (!isAccept) {
        this.$message.error('应该选择image/*类型的文件')
      }
      return isRightSize && isAccept
    },
    uploadSuccess(res, field){
      this.form[field] = res.path;
    },
    handleLawfirmChange(val) {
      this.form.lawfirmName = this.lawfirmList.find(item => item.id == val)?.lawfirmFullname
    }
  }
}
</script>

<style scoped>
.more-radio-group .el-radio{
  margin-top: 10px;
}
.other-input {
  margin-top: 8px;
}
</style>
